package com.dk.util;


import com.dk.enums.ResultEnum;

//统一返回包装类
public class Result<T> {
    private Integer code;
    private String message;
    private T data;


    //成功的
    public static Result ok(){
        return new Result(ResultEnum.SUCCESS.getIndex(), ResultEnum.SUCCESS.getName());
    }

    //通用的
    public static Result response(ResultEnum r){
        return new Result(r.getIndex(),r.getName());
    }

    public Result(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Result(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Result() {
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public Result setData(T data) {
        this.data = data;
        return this;
    }
}
